def testTolerance(list,tol): #needs list in form current, older, oldest
  #spectral radius method
  #n=list[-1]-list[-2] #numerator
  #specRad=n/(list[-2]-list[-3])
  #if 1-specRad!=0: check=n/((1-specRad)*list[-1]) #tol check
  #else:check=tol+1 #catches div. 0 error
  check=abs(list[0]-list[1])/(0.5*(list[0]+list[1]))
  if check<tol:return True
  else:
    return False

def writeOutput(mesh):
  pass

def doPhi(mesh,tol=0.001):
  mesh.updateBoundaries()
  for g in [1,2]: #do for fast and thermal, in that order
    i=0 #counts phi iterations
    converged=False
    while not converged:
      #mesh.newGen(g)
      i+=1
      for n in range(len(mesh.mus)):
        mesh.doTransport(g,n)
      converged=mesh.getPhi(g) #sets phi and checks convergence
      #converged=True #hack for debugging
      #loops back if not converged
    if g==1:i_fast=i
    else: i_therm=i
  return [i_fast,i_therm]
    #print 'Converged phi group',g,'in',i,'iterations.'
  #only gets to here if both fast and thermal converged
